#include <vector>

using namespace std;

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int val = INT32_MIN / 2;
        int ans = INT32_MIN / 2;
        for (int& num : nums) {
            val = max(val + num, num);
            ans = max(ans, val);
        }
        return ans;
    }
};